package glemipsc.instructions;

import glemipsc.Function;
import glemipsc.implementations.Argument;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class BaseInstruction implements Instruction {
	Instruction parent;

	@Override
	abstract public void computeInstruction(Argument result,
			List<glemipsc.implementations.Instruction> instructions,
			Function func);

	@Override
	abstract public int getNumberOfOperands();

	@Override
	abstract public Expression getOperand(int index);

	public Instruction getParent() {
		return parent;
	}

	public void setParent(Instruction parent) {
		this.parent = parent;
	}
	
	public int getInstructionsSize(List<glemipsc.implementations.Instruction> instructions) {
		int size = 0;
		
		Iterator<glemipsc.implementations.Instruction> iter = instructions.iterator();
		while (iter.hasNext()) {
			glemipsc.implementations.Instruction instr = iter.next();
			if (!instr.isNop())
				size++;
		}
		return size;
	}
	
}
